package com.dualPointer;

public class SquaresofaSortedArray0202_977 {
    public int[] sortedSquares(int[] nums) {
        int[] res = new int[nums.length];
        int i = res.length-1;

        int left = 0, right = nums.length-1;
        while (left <= right){
            int l = nums[left]*nums[left], r = nums[right]*nums[right];
            if(l>r){
                res[i] = l;
                i--;
                left++;
            }else {
                res[i] = r;
                i--;
                right--;
            }
        }
        return res;
    }
}
